package com.cloud.ceshi.controller;

import com.cloud.ceshi.api.RemoteCeshiService;
import com.cloud.common.core.domain.R;
import com.cloud.common.core.web.controller.BaseController;
import com.cloud.common.security.annotation.InnerAuth;
import com.cloud.system.api.RemoteUserService;
import com.cloud.system.api.model.LoginUser;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;

import java.math.BigInteger;
import java.security.SecureRandom;

/**
 * 参数配置 信息操作处理
 * 
 * @author cloud
 */
@RestController
@RequestMapping
@RefreshScope //动态刷新配置
@Tag(name = "测试模块")
public class CeshiController
{
    private static final int BIT_LENGTH = 128;

//模拟同态加密
    public static void main(String[] args) {
        BigInteger aliceInput = new BigInteger("10"); // Alice 的输入值
        BigInteger bobInput = new BigInteger("20"); // Bob 的输入值

        // 生成随机数
        SecureRandom random = new SecureRandom();
        BigInteger aliceRandom = new BigInteger(BIT_LENGTH, random);
        BigInteger bobRandom = new BigInteger(BIT_LENGTH, random);

        // 加密输入值 (x + a, y + b)
        BigInteger aliceEncrypted = aliceInput.add(aliceRandom);
        BigInteger bobEncrypted = bobInput.add(bobRandom);

        // 交换加密值
        BigInteger aliceReceived = bobEncrypted; // Alice 收到 y + b
        BigInteger bobReceived = aliceEncrypted; // Bob 收到 x + a

        // 部分解密 (y + b - a, x + a - b)
        BigInteger alicePart = aliceReceived.subtract(aliceRandom); // y + b - a
        BigInteger bobPart = bobReceived.subtract(bobRandom);      // x + a - b

        // 计算结果 (x + y) = (x + a - b) + (y + b - a)
        BigInteger result = alicePart.add(bobPart);

        System.out.println("Alice 输入值：" + aliceInput);
        System.out.println("Bob 输入值：" + bobInput);
        System.out.println("最终结果：" + result); // 应该输出30
    }

    @Value("${cloud.name}")
    private String name;
    @GetMapping("/list/{ddd}")
    @Operation(summary = "测试ddd")
    public R list(@PathVariable("ddd") Integer ddd)
    {
        int a=2/ddd;
        return R.ok(name+":"+a);
    }
    @Autowired
    private RemoteUserService remoteUserService;

    /**
     * 获取参数配置列表
     */
//    @InnerAuth
    @GetMapping("/list1/{ddd}")
    public R list1(@PathVariable("ddd") Integer ddd)
    {
        return R.ok(remoteUserService.list1(ddd));
    }
}
